package cn.hzking.gjmall.adpters.order;

import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.hzking.gjmall.R;
import cn.hzking.gjmall.app.Gjmall;
import cn.hzking.gjmall.bean.SureOrderBean;
import cn.hzking.gjmall.utils.IconTextSpanUtils;
import cn.hzking.gjmall.utils.PriceFormatUtils;

/**
 * Created by Administrator on 2018/4/3.
 */

public class SureOrderChildAdapter extends BaseQuickAdapter<SureOrderBean.DataBean.ItemHoldersBean.OrderItemsBean,BaseViewHolder> {
    public SureOrderChildAdapter(int layoutResId, @Nullable List<SureOrderBean.DataBean.ItemHoldersBean.OrderItemsBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, SureOrderBean.DataBean.ItemHoldersBean.OrderItemsBean item) {
        ImageView maxImage = helper.getView(R.id.sure_order_image);
        TextView tvTitle = helper.getView(R.id.sure_order_title);
        TextView tvDes = helper.getView(R.id.sure_order_color);
        TextView tvSuiFei = helper.getView(R.id.sure_order_suifei);
        TextView tvPrice = helper.getView(R.id.sure_order_newprice);
        TextView tvOlderPrice = helper.getView(R.id.sure_order_oldprice);
        TextView tvNum = helper.getView(R.id.sure_order_num);
        TextView tvActivity = helper.getView(R.id.sure_order_shuomin);
        //商品图片
        Glide.with(mContext).load(Gjmall.getOssHost()+item.getImageUrl()).placeholder(R.mipmap.xiangqing).error(R.mipmap.xiangqing).into(maxImage);
        //标题
        String title = item.getTitle();//标题
        String sellPattern = item.getSellpattern();//商品类型
        IconTextSpanUtils.setText(mContext, title, sellPattern, tvTitle);
        //描述
        tvDes.setText(String.valueOf(item.getSkuname()));
        //税费
        double taxPrice = item.getTaxPrice();
        if(taxPrice != 0){
            tvSuiFei.setVisibility(View.VISIBLE);
            String s = PriceFormatUtils.valueFormatWithTwo(String.valueOf(taxPrice));
            tvSuiFei.setText(s);
        }else {
            tvSuiFei.setVisibility(View.GONE);
        }
        //价格
        double price = item.getPrice();
        String newPrice = PriceFormatUtils.valueFormatWithTwo(String.valueOf(price));
        tvPrice.setText("¥"+newPrice);
        //旧价格
        double avecostPrice = item.getAvecostPrice();
        String oldPrice = PriceFormatUtils.valueFormatWithTwo(String.valueOf(avecostPrice));
        tvOlderPrice.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG); //中划线
        tvOlderPrice.setText("¥"+oldPrice);
        //活动说明
        //todo 接口没返回字段,后续处理
        if(item.getActiviteId() >0){//是活动
            tvActivity.setVisibility(View.VISIBLE);
        }else {
            tvActivity.setVisibility(View.INVISIBLE);
        }
        //数量
        tvNum.setText("x"+item.getNumber());



    }
}
